home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / OTHER_LA / QUINTA / DICTIONA.C < prev    next >
Text File  |  1990-08-16  |  21KB  |  954 lines

  1. /*
  2.  * Quinta    ⌐ 1990    Eric W. Sink
  3.  *
  4.  * This file contains functions relating to the dictionary
  5.  *
  6.  */
  7.  
  8. #include    "Q_includes.h"
  9.  
  10. /*--------------------------------------------------------------------*/
  11. int                         SingleAble(x, order)
  12.     long                        x;
  13.     int                         order;
  14. {
  15.     register int                index;
  16.     register int                result;
  17.     result = 1;
  18.     index = 0;
  19.     while ((index < order) && result)
  20.     {
  21.         result = result && ((digit(x, index) == (**control_cp).ClassIndex)
  22.              || (digit(x, index) == (**generic_cp).ClassIndex));
  23.         index++;
  24.     }
  25.     return result;
  26. }
  27. /*--------------------------------------------------------------------*/
  28. int                         Comment(name, str)
  29.     char                       *name;
  30.     char                       *str;
  31. {
  32.     MessageHandle                msg;
  33.     newQstringp(str);
  34.     msg = findmessagep(name, 0);
  35.     if (((**msg).comment))
  36.     {
  37.         DropHandle((void **) ((**msg).comment));
  38.     }
  39.     (**msg).comment = popstr();
  40. }
  41. /*--------------------------------------------------------------------*/
  42. long                        RespTableIndex(set)
  43.     ClassSet                    set;
  44. {
  45.     register QInt                index = 0;
  46.     register long                result;
  47.     result = 0;
  48.     while ((*set)[index])
  49.     {
  50.         result = result * MaxClasses + (**(((*set)[index]))).ClassIndex;
  51.         index++;
  52.         if (index > MaxHomes) {
  53.             QERROR(diaggeneral);
  54.         }
  55.     }
  56.     return result;
  57. }
  58. /*--------------------------------------------------------------------*/
  59. RespTagHandle               *ParentPtr(x)
  60.     RespTagHandle                x;
  61. {
  62.     if ((**x).parent)
  63.     {
  64.         if ((**((**x).parent)).right == x)
  65.         {
  66.             return &((**((**x).parent)).right);
  67.         }
  68.         else
  69.         {
  70.             return &((**((**x).parent)).left);
  71.         }
  72.     }
  73.     else
  74.     {
  75.         return &((**((**((**x).r)).message)).responselist);
  76.     }
  77. }
  78. /*--------------------------------------------------------------------*/
  79. int                         Rotate1Right(current, child)
  80.     RespTagHandle                current;
  81.     RespTagHandle                child;
  82. {
  83.     (**current).right = (**child).left;
  84.     (**child).left = current;
  85.     (*(ParentPtr(current))) = child;
  86.     (**child).parent = (**current).parent;
  87.     (**current).parent = child;
  88. }
  89. /*--------------------------------------------------------------------*/
  90. int                         Rotate1Left(current, child)
  91.     RespTagHandle                current;
  92.     RespTagHandle                child;
  93. {
  94.     (**current).left = (**child).right;
  95.     (**child).right = current;
  96.     (*(ParentPtr(current))) = child;
  97.     (**child).parent = (**current).parent;
  98.     (**current).parent = child;
  99. }
  100. /*--------------------------------------------------------------------*/
  101. int                         Rotate2Right(current, child, grandchild)
  102.     RespTagHandle                current;
  103.     RespTagHandle                child;
  104.     RespTagHandle                grandchild;
  105. {
  106.     (**current).right = (**grandchild).left;
  107.     (**child).left = (**grandchild).right;
  108.     (**grandchild).left = current;
  109.     (**grandchild).right = child;
  110.     (*(ParentPtr(current))) = grandchild;
  111.     (**grandchild).parent = (**current).parent;
  112.     (**current).parent = grandchild;
  113.     (**child).parent = grandchild;
  114. }
  115. /*--------------------------------------------------------------------*/
  116. int                         Rotate2Left(current, child, grandchild)
  117.     RespTagHandle                current;
  118.     RespTagHandle                child;
  119.     RespTagHandle                grandchild;
  120. {
  121.     (**current).left = (**grandchild).right;
  122.     (**child).right = (**grandchild).left;
  123.     (**grandchild).right = current;
  124.     (**grandchild).left = child;
  125.     (*(ParentPtr(current))) = grandchild;
  126.     (**grandchild).parent = (**current).parent;
  127.     (**current).parent = grandchild;
  128.     (**child).parent = grandchild;
  129. }
  130. /*--------------------------------------------------------------------*/
  131. int                         SetRespTablen(msg, n, resp)
  132.     MessageHandle                msg;
  133.     long                        n;
  134.     ResponseHandle                resp;
  135. {
  136.     /* This has become a long routine... */
  137.  
  138.     register QInt                done;
  139.     register RespTagHandle        x;
  140.     register RespTagHandle        y;
  141.     register RespTagHandle        last;
  142.     register RespTagHandle        child;
  143.     register RespTagHandle        grandchild;
  144.     register RespTagHandle        current;
  145.     register RespTagHandle        tr;
  146.     register RespTagHandle        newtr;
  147.     if (SingleAble(n, (**msg).order) &&
  148.     ((**msg).single != (ResponseHandle) - 1))
  149.     {
  150.         if (!(**msg).responselist)
  151.         {
  152.             (**msg).single = resp;
  153.         }
  154.     }
  155.     else
  156.     {
  157.         if ((**msg).single)
  158.         {
  159.             if ((**msg).single != (ResponseHandle) - 1)
  160.             {
  161.                 if (resp != (**msg).single)
  162.                 {
  163.                     ResponseHandle                temp;
  164.                     temp = (**msg).single;
  165.                     (**msg).single = (ResponseHandle) - 1;
  166.                     (**msg).responselist = NULL;
  167.                     AddTable2((**temp).HomesIndex, msg, temp, 1);
  168.                 }
  169.             }
  170.             else
  171.             {
  172.                 (**msg).single = NULL;
  173.             }
  174.         }
  175.     }
  176.     if ((**msg).single)
  177.     {
  178.         (**msg).RespCount = 1;
  179.         (**msg).responselist = NULL;
  180.         return;
  181.     }
  182.     /* If we made it to here, then the tree must be manipulated... */
  183.     /*
  184.      * First, find out if the node we seek is in the tree.    After this
  185.      * loop, done == 1 indicates that the node does not exist.    done==2
  186.      * indicates that the node was found and its handle is in x
  187.      */
  188.     x = (**msg).responselist;
  189.     done = 0;
  190.     last = NULL;
  191.     while (!done)
  192.     {
  193.         if (x)
  194.         {
  195.             if (((**x).index) == n)
  196.             {
  197.                 done = 2;
  198.             }
  199.             else if ((**x).index > n)
  200.             {
  201.                 last = x;
  202.                 x = (**x).left;
  203.             }
  204.             else
  205.             {
  206.                 last = x;
  207.                 x = (**x).right;
  208.             }
  209.         }
  210.         else
  211.         {
  212.             done = 1;
  213.         }
  214.     }
  215.     if (done == 2)
  216.     {
  217.         if (!resp)
  218.         {
  219.             /*
  220.              * if we set a resp to NULL, we really Delete the
  221.              * response
  222.              */
  223.             if ((**x).r)
  224.             {    /* the else case should never happen */
  225.                 child = x;
  226.                 current = (**x).parent;
  227.                 done = 0;
  228.                 while (!done)
  229.                 {
  230.                     switch ((**current).condcode)
  231.                     {
  232.                     case 0:
  233.                         if ((**current).right == child)
  234.                         {
  235.                             (**current).condcode = -1;
  236.                         }
  237.                         else
  238.                         {
  239.                             (**current).condcode = 1;
  240.                         }
  241.                         done++;
  242.                         break;
  243.                     case 1:
  244.                         if ((**current).left == child)
  245.                         {
  246.                             /* step 3 */
  247.                             switch ((**((**current).right)).condcode)
  248.                             {
  249.                             case 0:
  250.                                 Rotate1Right(current, child);
  251.                                 (**current).condcode = 1;
  252.                                 (**child).condcode = -1;
  253.                                 done++;
  254.                                 break;
  255.                             case 1:
  256.                                 Rotate1Right(current, child);
  257.                                 (**current).condcode = 0;
  258.                                 (**child).condcode = 0;
  259.                                 current = child;
  260.                                 break;
  261.                             case -1:
  262.                                 grandchild = (**child).left;
  263.                                 Rotate2Right(current, child, grandchild);
  264.                                 if (!(**grandchild).condcode)
  265.                                 {
  266.                                     (**current).condcode = 0;
  267.                                     (**child).condcode = 0;
  268.                                 }
  269.                                 else
  270.                                 {
  271.                                     if ((**grandchild).condcode == 1)
  272.                                     {
  273.                                         (**current).condcode = -1;
  274.                                         (**child).condcode = 0;
  275.                                     }
  276.                                     else
  277.                                     {
  278.                                         (**current).condcode = 0;
  279.                                         (**child).condcode = 1;
  280.                                     }
  281.                                 }
  282.                                 (**grandchild).condcode = 0;
  283.                                 current = grandchild;
  284.                                 break;
  285.                             }
  286.                         }
  287.                         else
  288.                         {
  289.                             (**current).condcode = 0;
  290.                         }
  291.                         break;
  292.                     case -1:
  293.                         if ((**current).left == child)
  294.                         {
  295.                             (**current).condcode = 0;
  296.                         }
  297.                         else
  298.                         {
  299.                             /*
  300.                              * step 4 - mirror image
  301.                              * of above
  302.                              */
  303.                             switch ((**((**current).left)).condcode)
  304.                             {
  305.                             case 0:
  306.                                 Rotate1Left(child, current);
  307.                                 (**current).condcode = 1;
  308.                                 (**child).condcode = -1;
  309.                                 done++;
  310.                                 break;
  311.                             case 1:
  312.                                 Rotate1Left(child, current);
  313.                                 (**current).condcode = 0;
  314.                                 (**child).condcode = 0;
  315.                                 current = child;
  316.                                 break;
  317.                             case -1:
  318.                                 grandchild = (**child).right;
  319.                                 Rotate2Left(child, current, grandchild);
  320.                                 if (!(**grandchild).condcode)
  321.                                 {
  322.                                     (**current).condcode = 0;
  323.                                     (**child).condcode = 0;
  324.                                 }
  325.                                 else
  326.                                 {
  327.                                     if ((**grandchild).condcode == 1)
  328.                                     {
  329.                                         (**current).condcode = -1;
  330.                                         (**child).condcode = 0;
  331.                                     }
  332.                                     else
  333.                                     {
  334.                                         (**current).condcode = 0;
  335.                                         (**child).condcode = 1;
  336.                                     }
  337.                                 }
  338.                                 (**grandchild).condcode = 0;
  339.                                 current = grandchild;
  340.                                 break;
  341.                             }
  342.                         }
  343.                         break;
  344.                     }
  345.                 }
  346.                 if ((**x).left)
  347.                 {
  348.                     if ((**x).right)
  349.                     {
  350.                         tr = (**x).left;
  351.                         while ((**tr).right)
  352.                         {
  353.                             tr = (**tr).right;
  354.                         }
  355.                         newtr = tr;
  356.                     }
  357.                     else
  358.                     {
  359.                         newtr = (**x).left;
  360.                     }
  361.                 }
  362.                 else
  363.                 {
  364.                     if ((**x).right)
  365.                     {
  366.                         newtr = (**x).right;
  367.                     }
  368.                     else
  369.                     {
  370.                         newtr = NULL;
  371.                     }
  372.                 }
  373.                 (*(ParentPtr(x))) = newtr;
  374.                 (**msg).RespCount--;
  375.                 DropHandle((void **) x);
  376.             }
  377.         }
  378.         else
  379.         {
  380.             (**x).r = resp;
  381.         }
  382.  
  383.     }
  384.     else
  385.     {
  386.         if (resp)
  387.         {
  388.             (**msg).RespCount++;
  389.             y = (RespTagHandle) GetHandle((Size) sizeof(RespTagStruct));
  390.             (**y).index = n;
  391.             (**y).r = resp;
  392.             (**y).parent = last;
  393.             (**y).condcode = 0;
  394.             (**y).left = NULL;
  395.             (**y).right = NULL;
  396.             if (last)
  397.             {
  398.                 if ((**last).index > n)
  399.                 {
  400.                     (**last).left = y;
  401.                 }
  402.                 else
  403.                 {
  404.                     (**last).right = y;
  405.                 }
  406.             }
  407.             else
  408.             {
  409.                 (**msg).responselist = y;
  410.             }
  411.             /* Now rebalance the tree, if necessary */
  412.             x = (**y).parent;
  413.             child = y;
  414.             grandchild = NULL;
  415.             done = !x;
  416.             while (!done)
  417.             {
  418.                 switch ((**x).condcode)
  419.                 {
  420.                 case 0:
  421.                     if (child == (**x).right)
  422.                     {
  423.                         (**x).condcode = 1;
  424.                     }
  425.                     else if (child == (**x).left)
  426.                     {
  427.                         (**x).condcode = -1;
  428.                     }
  429.                     grandchild = child;
  430.                     child = x;
  431.                     x = (**x).parent;
  432.                     done = !x;
  433.                     break;
  434.                 case 1:
  435.                     if (child == (**x).right)
  436.                     {
  437.                         /* rebalance */
  438.                         if (grandchild == (**child).right)
  439.                         {
  440.                             (**x).right = (**child).left;
  441.                             (**child).left = x;
  442.                             if ((**x).parent)
  443.                             {
  444.                                 if ((**((**x).parent)).left == x)
  445.                                 {
  446.                                     (**((**x).parent)).left = child;
  447.                                 }
  448.                                 else
  449.                                 {
  450.                                     (**((**x).parent)).right = child;
  451.                                 }
  452.                             }
  453.                             else
  454.                             {
  455.                                 (**msg).responselist = child;
  456.                             }
  457.                             (**child).parent = (**x).parent;
  458.                             (**x).parent = child;
  459.                             (**((**x).right)).parent = x;
  460.                             (**x).condcode = 0;
  461.                             (**child).condcode = 0;
  462.                         }
  463.                         else
  464.                         {
  465.                             (**x).right = (**grandchild).left;
  466.                             (**grandchild).left = x;
  467.                             (**child).left = (**grandchild).right;
  468.                             (**grandchild).right = child;
  469.                             if ((**x).parent)
  470.                             {
  471.                                 if ((**((**x).parent)).left == x)
  472.                                 {
  473.                                     (**((**x).parent)).left = grandchild;
  474.                                 }
  475.                                 else
  476.                                 {
  477.                                     (**((**x).parent)).right = grandchild;
  478.                                 }
  479.                             }
  480.                             else
  481.                             {
  482.                                 (**msg).responselist = grandchild;
  483.                             }
  484.                             (**grandchild).parent = (**x).parent;
  485.                             (**child).parent = grandchild;
  486.                             (**x).parent = grandchild;
  487.                             (**((**x).right)).parent = x;
  488.                             (**((**child).left)).parent = child;
  489.                             if ((**y).index > (**grandchild).index)
  490.                             {
  491.                                 (**child).condcode = -1;
  492.                                 (**x).condcode = 0;
  493.                             }
  494.                             else if ((**y).index < (**grandchild).index)
  495.                             {
  496.                                 (**child).condcode = 0;
  497.                                 (**x).condcode = 1;
  498.                             }
  499.                             else
  500.                             {
  501.                                 (**child).condcode = 0;
  502.                                 (**x).condcode = 0;
  503.                                 (**grandchild).condcode = 0;
  504.                             }
  505.                         }
  506.                     }
  507.                     else if (child == (**x).left)
  508.                     {
  509.                         (**x).condcode = 0;
  510.                     }
  511.                     done = 1;
  512.                     break;
  513.                 case -1:
  514.                     if (child == (**x).right)
  515.                     {
  516.                         (**x).condcode = 0;
  517.                     }
  518.                     else if (child == (**x).left)
  519.                     {
  520.                         /* rebalance */
  521.                         if (grandchild == (**child).left)
  522.                         {
  523.                             (**x).left = (**child).right;
  524.                             (**child).right = x;
  525.                             if ((**x).parent)
  526.                             {
  527.                                 if ((**((**x).parent)).right == x)
  528.                                 {
  529.                                     (**((**x).parent)).right = child;
  530.                                 }
  531.                                 else
  532.                                 {
  533.                                     (**((**x).parent)).left = child;
  534.                                 }
  535.                             }
  536.                             else
  537.                             {
  538.                                 (**msg).responselist = child;
  539.                             }
  540.                             (**child).parent = (**x).parent;
  541.                             (**x).parent = child;
  542.                             (**((**x).left)).parent = x;
  543.                             (**x).condcode = 0;
  544.                             (**child).condcode = 0;
  545.                         }
  546.                         else
  547.                         {
  548.                             (**x).left = (**grandchild).right;
  549.                             (**grandchild).right = x;
  550.                             (**child).right = (**grandchild).left;
  551.                             (**grandchild).left = child;
  552.                             if ((**x).parent)
  553.                             {
  554.                                 if ((**((**x).parent)).right == x)
  555.                                 {
  556.                                     (**((**x).parent)).right = grandchild;
  557.                                 }
  558.                                 else
  559.                                 {
  560.                                     (**((**x).parent)).left = grandchild;
  561.                                 }
  562.                             }
  563.                             else
  564.                             {
  565.                                 (**msg).responselist = grandchild;
  566.                             }
  567.                             (**grandchild).parent = (**x).parent;
  568.                             (**child).parent = grandchild;
  569.                             (**x).parent = grandchild;
  570.                             (**((**x).left)).parent = x;
  571.                             (**((**child).right)).parent = child;
  572.                             if ((**y).index < (**grandchild).index)
  573.                             {
  574.                                 (**child).condcode = 1;
  575.                                 (**x).condcode = 0;
  576.                             }
  577.                             else if ((**y).index < (**grandchild).index)
  578.                             {
  579.                                 (**child).condcode = 0;
  580.                                 (**x).condcode = -1;
  581.                             }
  582.                             else
  583.                             {
  584.                                 (**child).condcode = 0;
  585.                                 (**x).condcode = 0;
  586.                                 (**grandchild).condcode = 0;
  587.                             }
  588.                         }
  589.                     }
  590.                     done = 1;
  591.                     break;
  592.                 }
  593.             }
  594.         }
  595.     }
  596. }
  597. /*--------------------------------------------------------------------*/
  598. ResponseHandle                GetRespMn(msg, n)
  599.     MessageHandle                msg;
  600.     long                        n;
  601. {
  602.     register QInt                done;
  603.     register RespTagHandle        x;
  604.     register RespTagHandle        last;
  605.     if (x = (RespTagHandle) (**msg).single)
  606.     {
  607.         return (ResponseHandle) x;
  608.     }
  609.     x = (**msg).responselist;
  610.     done = 0;
  611.     last = NULL;
  612.     while (!done)
  613.     {
  614.         if (x)
  615.         {
  616.             if (((**(x)).index) == n)
  617.             {
  618.                 done = 2;
  619.             }
  620.             else if ((**x).index > n)
  621.             {
  622.                 last = x;
  623.                 x = (**x).left;
  624.             }
  625.             else
  626.             {
  627.                 last = x;
  628.                 x = (**x).right;
  629.             }
  630.         }
  631.         else
  632.         {
  633.             done = 1;
  634.         }
  635.     }
  636.     if (done == 2)
  637.     {
  638.         return (**x).r;
  639.     }
  640.     else
  641.     {
  642.         return NULL;
  643.     }
  644. }
  645. /*--------------------------------------------------------------------*/
  646. long                        Hash1(s)
  647.     QStr                        s;
  648. {
  649.     return (((char) (**s)) * ((long) (((long) (MaxTotalMessages / 128)) % (long) MaxTotalMessages)));
  650. }
  651. /*--------------------------------------------------------------------*/
  652. #ifndef applec
  653. long                        power(x, y)
  654.     long                        x, y;
  655. {
  656.     if (y == 1)
  657.     {
  658.         return x;
  659.     }
  660.     else if (!y)
  661.     {
  662.         return (long) 1;
  663.     }
  664.     else
  665.     {
  666.         return x * power(x, y - 1);
  667.     }
  668. }
  669. #endif
  670. /*--------------------------------------------------------------------*/
  671. MessageHandle                findmessage(name, create)
  672.     QStr                        name;
  673.     QInt                        create;
  674. {
  675.     register QInt                hashindex, startsearch;
  676.     register long                index;
  677.     register long                numresps;
  678.  
  679.     register MessageHandle        found;
  680.  
  681.     hashindex = Hash1(name);
  682.     startsearch = hashindex - 1;
  683.     found = NULL;
  684.     while ((!found) && startsearch != hashindex)
  685.     {
  686.         if (((*GlobalMsgTable)[hashindex]))
  687.         {
  688.             if (!Qstrcmp(name, (**((*GlobalMsgTable)[hashindex])).name))
  689.             {
  690.                 found = ((*GlobalMsgTable)[hashindex]);
  691.             }
  692.             else
  693.             {
  694.                 hashindex = (hashindex + 1) % MaxTotalMessages;
  695.             }
  696.         }
  697.         else
  698.         {
  699.             hashindex = (hashindex + 1) % MaxTotalMessages;
  700.         }
  701.     }
  702.  
  703.  
  704.     if ((!found) && create)
  705.     {
  706.         found = (MessageHandle) GetHandle((Size) sizeof(messagenode));
  707.         (**found).name = (QStr) GetHandle((Size) MAXNAMELENGTH);
  708.         (**found).RespCount = 0;
  709.         (**found).RespMax = MaxClasses;
  710.         (**found).comment = NULL;
  711.         (**found).order = create;
  712.         (**found).TableIndex = MaxTotalMessages + 1;
  713.         numresps = (**found).RespMax;
  714.         (**found).responselist = NULL;
  715.         (**found).single = NULL;
  716.         Qstrcpy((**found).name, name);
  717.         (**found).status = 0;
  718.         AssignTableIndex(found);
  719.     }
  720.     return found;
  721. }
  722. /*--------------------------------------------------------------------*/
  723. MessageHandle                findmessagep(name, create)
  724.     char                       *name;
  725.     QInt                        create;
  726. {
  727.     char                       *pointer;
  728.     pointer = name;
  729.     return findmessage(&pointer, create);
  730. }
  731. /*--------------------------------------------------------------------*/
  732. MessageHandle                killmessage(name)
  733.     QStr                        name;
  734. {
  735.     MessageHandle                temp;
  736.     MessageHandle                found;
  737.     MessageHandle                last;
  738.     found = findmessage(name, 0);
  739.  
  740.     (*GlobalMsgTable)[(**found).TableIndex] = NULL;
  741.     DropHandle((void **) (**found).name);
  742.     if ((**found).comment)
  743.     {
  744.         DropHandle((void **) (**found).comment);
  745.     }
  746.     DropHandle((void **) found);
  747. }
  748. /*--------------------------------------------------------------------*/
  749. QInt                        Inherited1(msg, n)
  750.     MessageHandle                msg;
  751.     long                        n;
  752. {
  753.     register long                x, y;
  754.     register ResponseHandle     r;
  755.     x = n;
  756.     y = -1;
  757.     if (r = GetRespMn(msg, n))
  758.     {
  759.         y = (**r).HomesIndex;
  760.     }
  761.     return (x != y);
  762. }
  763. /*--------------------------------------------------------------------*/
  764. int                         CountResponses(tree)
  765.     RespTagHandle                tree;
  766. {
  767.     register ResponseHandle     resp;
  768.     register int                count;
  769.     count = 0;
  770.     if ((**tree).left)
  771.     {
  772.         count += CountResponses((**tree).left);
  773.     }
  774.     if ((**tree).right)
  775.     {
  776.         count += CountResponses((**tree).right);
  777.     }
  778.     resp = (**tree).r;
  779.     if (resp)
  780.     {
  781.         if (!Inherited1((**resp).message, (**tree).index))
  782.         {
  783.             count++;
  784.         }
  785.     }
  786.     return count;
  787. }
  788. /*--------------------------------------------------------------------*/
  789. QInt                        NumDefined(index)
  790.     long                        index;
  791. {
  792.     /*
  793.      * MultiMessage inheritance: a response can be passed to all subclasses
  794.      * simply by iterating over the subclasses and copying the response
  795.      * handle to all the apprpriate places in the RespTable for that Message.
  796.      * A given resptable entry can be determined if it was inherited or not
  797.      * by comparing the RespTableIndex of the entry with the RespTableIndex
  798.      * of the Homes Set in the Response Record.  If not equal, the resp is
  799.      * inherited.
  800.      */
  801.     MessageHandle                msg;
  802.  
  803.     msg = (*GlobalMsgTable)[index];
  804.     if ((**msg).single)
  805.     {
  806.         return 1;
  807.     }
  808.     else if ((**msg).responselist)
  809.     {
  810.         return CountResponses((**msg).responselist);
  811.     }
  812.     else
  813.     {
  814.         return 0;
  815.     }
  816. }
  817. /*--------------------------------------------------------------------*/
  818. int                         remove_response(resp, oldresp)
  819.     ResponseHandle                resp;
  820.     ResponseHandle                oldresp;
  821. {
  822.     MessageHandle                msg;
  823.     ResponseHandle                prev;
  824.     ResponseHandle                dead;
  825.     ClassHandle                 cls;
  826.     register long                index;
  827.     register long                RespIndex;
  828.     msg = (**resp).message;
  829.     index = (**msg).TableIndex;
  830.  
  831.     RespIndex = (**resp).HomesIndex;
  832.     SetRespTablen(msg, RespIndex, NULL);
  833.  
  834.     if (oldresp)
  835.     {
  836.         AddTable2(RespIndex, msg, oldresp, 1);
  837.     }
  838.  
  839.     if (!NumDefined(index))
  840.     {
  841.         killmessage((**msg).name);
  842.     }
  843.     if ((**resp).parms)
  844.     {
  845.         DropHandle((void **) (**resp).parms);
  846.     }
  847.     DropHandle((void **) resp);
  848. }
  849. /*--------------------------------------------------------------------*/
  850. ResponseHandle                newresponse(code, numparms)
  851.     int                         (*code) ();
  852.     QInt                        numparms;
  853. {
  854.     register ResponseHandle     result;
  855.     register long                index;
  856.     result = (ResponseHandle) GetHandle((Size) sizeof(dictelement));
  857.     (**result).code = code;
  858.     (**result).status = 0;
  859.     (**result).HomesIndex = (long) 0;
  860.     (**result).message = NULL;
  861.  
  862.     (**result).numparms = numparms;
  863.     if (numparms)
  864.     {
  865.         index = numparms;
  866.         (**result).parms = (MessageHandle **) GetHandle((Size) index * sizeof(MessageHandle));
  867.         while (index)
  868.         (*((**result).parms))[--index] = NULL;
  869.     }
  870.     else
  871.     {
  872.         (**result).parms = NULL;
  873.     }
  874.     return result;
  875. }
  876. /*--------------------------------------------------------------------*/
  877. int                         insertresp(setindex, newdict, msg)
  878.     long                        setindex;
  879.     ResponseHandle                newdict;
  880.     MessageHandle                msg;
  881. {
  882.     register QInt                index;
  883.     (**newdict).HomesIndex = setindex;
  884.     (**newdict).message = msg;
  885.     AddTable2(setindex, msg, newdict, 1);
  886. }
  887. /*--------------------------------------------------------------------*/
  888. int                         AssignTableIndex(msg)
  889.     MessageHandle                msg;
  890. {
  891.     register QInt                resultindex = 0;
  892.     resultindex = Hash1((**msg).name);
  893.     if (((*GlobalMsgTable)[resultindex]))
  894.     {
  895.         while (((*GlobalMsgTable)[resultindex]))
  896.         resultindex = (resultindex + 1) % MaxTotalMessages;
  897.     }
  898.     (*GlobalMsgTable)[resultindex] = msg;
  899.     (**msg).TableIndex = resultindex;
  900. }
  901. /*--------------------------------------------------------------------*/
  902. int                         AddTable2(respindex, msg, resp, toprecurs)
  903.     long                        respindex;
  904.     MessageHandle                msg;
  905.     ResponseHandle                resp;
  906.     QInt                        toprecurs;
  907. {
  908.     register QInt                index, index2;
  909.     register QInt                clsindex;
  910.     register QInt                tempdigit;
  911.     register long                subindex;
  912.     register ClassSet            mytempset;
  913.     register ClassSet            subs;
  914.     ResponseHandle theresp;
  915.     
  916.     theresp = GetRespMn(msg,respindex);
  917.  
  918.     if (!theresp)
  919.     {
  920.         SetRespTablen(msg, respindex, resp);
  921.     }
  922.     else if ((respindex != ((**theresp).HomesIndex)) &&
  923.         ((**theresp).HomesIndex == (**resp).HomesIndex) )
  924.     {
  925.         SetRespTablen(msg, respindex, resp);
  926.     }
  927.     else if (toprecurs)
  928.     {
  929.         SetRespTablen(msg, respindex, resp);
  930.     }
  931.  
  932.     /* Then set for all subclasses */
  933.     if (!(**msg).single)
  934.     {
  935.         index2 = 0;
  936.         while (index2 < (**msg).order)
  937.         {
  938.             clsindex = 0;
  939.             tempdigit = digit((long) respindex, (short) index2);
  940.             subs = ((**((*ClassTable)[tempdigit])).subclasses);
  941.             while ((*subs)[clsindex])
  942.             {
  943.                 subindex = subst((long) respindex, (short) index2,
  944.                          (short) tempdigit,
  945.                 (short) (**((*subs)[clsindex])).ClassIndex);
  946.                 AddTable2(subindex, msg, resp, 0);
  947.                 clsindex++;
  948.             }
  949.             index2++;
  950.         }
  951.     }
  952. }
  953. /*--------------------------------------------------------------------*/
  954.